package jieduan1_part4;

import java.util.concurrent.locks.ReentrantLock;

public class TicketRunnableTest implements Runnable {
    private static int tickets = 100;
    private ReentrantLock lock = new ReentrantLock();
    @Override
    public void run() {
        while (true){
            lock.lock();
            if (tickets<0){
                break;
            }else {

                System.out.println(Thread.currentThread()+"------"+"这是第"+tickets-- + "号票");
            }
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        TicketRunnableTest ticketRunnableTest = new TicketRunnableTest();
        new Thread(ticketRunnableTest).start();
        new Thread(ticketRunnableTest).start();
        new Thread(ticketRunnableTest).start();
    }
}
